<script setup>
import { ref, reactive } from 'vue'

// 批量操作筛选条件
const filters = reactive({
  topicId: null,
  timeRange: null,
  contentKey: '',
  minHot: null,
  maxHot: null,
  startLikeNum: null,
  endLikeNum: null,
  startCollectNum: null,
  endCollectNum: null,
  startViewNum: null,
  endViewNum: null,
  isNameless: null
})

// 限流设置
const limitSettings = reactive({
  maxHot: 500,
  decreaseValue: 10,
  decreaseInterval: 30,
  affectCount: 10
})

// 预览数据
const previewPosts = ref([])
const showPreview = ref(false)

// 获取预览数据
const getPreviewPosts = () => {
  // TODO: 调用API获取符合条件的帖子
  showPreview.value = true
}

// 执行批量限流
const executeBatchLimit = () => {
  // TODO: 调用API执行批量限流
}

// 添加抽屉控制
const drawerVisible = ref(false)

// 打开抽屉
const openFilterDrawer = () => {
  drawerVisible.value = true
}

// 应用筛选
const applyFilters = () => {
  drawerVisible.value = false
  getPreviewPosts()
}
</script>

<template>
  <div class="batch-limit">
    <!-- 筛选按钮 -->
    <div class="filter-trigger">
      <el-button type="primary" @click="openFilterDrawer">
        <el-icon><Filter /></el-icon>
        筛选条件
      </el-button>
    </div>

    <!-- 限流设置 -->
    <el-card class="batch-settings">
      <template #header>
        <div class="card-header">
          <span>批量限流设置</span>
        </div>
      </template>
      <el-form label-width="120px">
        <el-form-item label="最大热度值">
          <el-input-number v-model="limitSettings.maxHot" :min="0" />
        </el-form-item>
        <el-form-item label="递减值">
          <el-input-number v-model="limitSettings.decreaseValue" :min="1" />
        </el-form-item>
        <el-form-item label="递减间隔(分钟)">
          <el-input-number v-model="limitSettings.decreaseInterval" :min="1" />
        </el-form-item>
        <el-form-item label="影响帖子数量">
          <el-input-number v-model="limitSettings.affectCount" :min="1" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="getPreviewPosts">预览</el-button>
        </el-form-item>
      </el-form>
    </el-card>

    <!-- 预览区域 -->
    <div v-if="showPreview" class="preview-section">
      <el-card>
        <template #header>
          <div class="card-header">
            <span>预览结果</span>
            <el-button type="primary" @click="executeBatchLimit">确认执行</el-button>
          </div>
        </template>
        <el-table :data="previewPosts" border style="width: 100%">
          <el-table-column prop="title" label="帖子标题" />
          <el-table-column prop="topic" label="话题" />
          <el-table-column prop="author" label="发布者" />
          <el-table-column prop="createTime" label="发布时间" />
          <el-table-column prop="hot" label="当前热度" />
          <el-table-column prop="targetHot" label="目标热度" />
        </el-table>
      </el-card>
    </div>

    <!-- 筛选条件抽屉 -->
    <el-drawer
      v-model="drawerVisible"
      title="筛选条件"
      direction="rtl"
      size="450px"
    >
      <template #default>
        <el-form>
          <!-- 将原有的筛选表单移到这里 -->
          <el-form-item label="话题">
            <el-select v-model="filters.topicId" placeholder="选择话题" clearable>
              <el-option
                v-for="item in topics"
                :key="item.id"
                :label="item.title"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
          <!-- ... 其他筛选条件 ... -->
        </el-form>
      </template>
      <template #footer>
        <div style="flex: auto">
          <el-button @click="drawerVisible = false">取消</el-button>
          <el-button type="primary" @click="applyFilters">应用</el-button>
        </div>
      </template>          
    
    </el-drawer>
  </div>
</template>

<style scoped>
.batch-limit {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.filter-trigger {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 8px;
}

.limit-settings,
.preview-section {
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
}

/* ... 其他样式与 BatchFlow 相同 ... */
</style>